#!/bin/bash

#fix permissions
chmod +x /Applications/Pipeline.app/Contents/MacOS/Pipeline   
chmod +x /Applications/Pipeline.app/Contents/MonoBundle/ffmpeg
chmod +x /Applications/Pipeline.app/Contents/MonoBundle/ffprobe
chmod +x /Applications/Pipeline.app/Contents/MonoBundle/mono
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -v -f /Applications/Pipeline.app

#mgcb terminal command
if [ ! -d /usr/local/bin ]
then
	if [ ! -d /usr/local ]
	then
		mkdir /usr/local
	fi
        chgrp -R admin /usr/local
	chmod -R 755 /usr/local
	mkdir /usr/local/bin
fi
if [ -f /usr/local/bin/mgcb ]
then
	rm /usr/local//bin/mgcb
fi
echo "#!/bin/bash
mono /Applications/Pipeline.app/Contents/MonoBundle/MGCB.exe \"\$@\"" >> /usr/local/bin/mgcb
chmod u+x /usr/local/bin/mgcb
#write an uninstaller
if [ -f /usr/local/bin/monogame-uninstall ]
then
	rm /usr/local/bin/monogame-uninstall
fi
echo "#!/bin/bash

sudo rm -Rf '/Applicatons/Pipeline.app/'
sudo pkgutil --forget com.monogame.pipeline
if [ -d '/Applications/Xamarin Studio.app' ]
then
  /Applications/Xamarin\ Studio.app/Contents/MacOS/mdtool setup uninstall MonoDevelop.MonoGame -y
fi
if [ ! -d '/Library/Frameworks/Mono.framework/Versions/4.6.2' ]
	ln -s /Library/Frameworks/Mono.framework/Versions/Current /Library/Frameworks/Mono.framework/Versions/4.6.2
fi
sudo rm /usr/local/bin/mgcb
sudo rm /usr/local/bin/monogame-uninstall
" >> /usr/local/bin/monogame-uninstall
chmod +x /usr/local/bin/monogame-uninstall
